//
//  ModefiyController.m
//  FastDoctor
//
//  Created by apple on 16/7/7.
//  Copyright © 2016年 sc. All rights reserved.
//

#import "ModefiyController.h"
#import "SignViewController.h"

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS



#import <Masonry.h>
#define kFilePath(fileName) ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:fileName])

@interface ModefiyController()
@property(nonatomic,weak)UITextField *userName;
@property(nonatomic,weak)UITextField *passWord;

@end
@implementation ModefiyController
-(void)viewDidLoad{
    [super viewDidLoad];
    [self showTextfield];
    [self showButton];
}

//刚进去的界面
-(void)showTextfield{
    
    //用户名textField
    UITextField *userName = [[UITextField alloc] init];
    self.userName = userName;
    userName.backgroundColor =[UIColor colorWithRed:241/255.0 green:240/255.0 blue:247/255.0 alpha:1];
    [self.view addSubview:userName];
    
    //设置用户名textField的约束
    [userName makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view).offset(120);
        make.centerX.equalTo(self.view.centerX);
        make.width.equalTo(@200);
        make.height.equalTo(@30);
    }];
    
    //用户名label
    UILabel *userLabel = [[UILabel alloc] init];
    userLabel.text = @"用户名";
    
    if (kDevice_Is_iPhone5)
    {
         userLabel.font = [UIFont systemFontOfSize:13];
    }
    else if(kDevice_Is_iPhone6Plus)
    {
         userLabel.font = [UIFont systemFontOfSize:17];
    }
    else
    {
        userLabel.font = [UIFont systemFontOfSize:15];
    }
    
   
    [userLabel sizeToFit];
    
    [self.view addSubview:userLabel];
    
    //设置约束
    [userLabel makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(userName.left).offset(-10);
        make.centerY.equalTo(userName.centerY);
    }];
    
    
    //密码textField
    UITextField *passWord = [[UITextField alloc] init];
    self.passWord =passWord;

    passWord.backgroundColor =[UIColor colorWithRed:241/255.0 green:240/255.0 blue:247/255.0 alpha:1];
    [self.view addSubview:passWord];
    
    //设置用户名textField的约束
    [passWord makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(userName.bottom).offset(30);
        make.centerX.equalTo(self.view.centerX);
        make.width.equalTo(@200);
        make.height.equalTo(@30);
    }];
    
    
    //密码label
    UILabel *passWordLabel = [[UILabel alloc] init];
    passWordLabel.text = @"密码";
    
    if (kDevice_Is_iPhone5)
    {
        passWordLabel.font = [UIFont systemFontOfSize:13];
    }
    else if(kDevice_Is_iPhone6Plus)
    {
        passWordLabel.font = [UIFont systemFontOfSize:17];
    }
    else
    {
        passWordLabel.font = [UIFont systemFontOfSize:15];
    }
    
    
    [passWordLabel sizeToFit];
    
    [self.view addSubview:passWordLabel];
    
    //设置约束
    [passWordLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(passWord.left).offset(-10);
        make.centerY.equalTo(passWord.centerY);
    }];
    
    
    
    
    
    
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults]objectForKey:@"account"];
    
    NSString *username = dict[@"username"];
    NSString *password = dict[@"password"];
    userName.text = username;
    passWord.text = password;
    
    
    
    userName.userInteractionEnabled = NO;
    [passWord becomeFirstResponder];
 }
-(void)showButton{
    UIButton *confirmButton = [[UIButton alloc]init];
    
    [self.view addSubview:confirmButton];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passWord).offset(100);
        make.width.equalTo(@150);
        make.centerX.equalTo(self.view);
        make.height.equalTo(@50);
        
    }];
    [confirmButton setTitle:@"确认" forState:UIControlStateNormal];
     
    confirmButton.backgroundColor = [UIColor colorWithRed:0/255.0 green:199/255.0 blue:212/255.0 alpha:1];

    [confirmButton addTarget:self action:@selector(didClick:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)didClick:(UIButton *)button{
    
    [[NSUserDefaults standardUserDefaults]setObject:@{@"username":self.userName.text,@"password":self.passWord.text} forKey:@"account"];
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
@end
